package eu.news.servlet.admin.system;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import eu.news.data.hibernate.dao.HB_SysConfigDAO;
import eu.news.data.pojo.SysConfig;

/**
 * URI /admin/system/config/delete
 */
public class DeleteConfig extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * Function:删除系统配置项 
	 * Input:键值 
	 * Output: 
	 * 		200：成功 
	 * 		其他:错误信息
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String key = request.getParameter("key");
		response.setCharacterEncoding("UTF-8");
		if (key != null && key.trim().length() > 0) {
			HB_SysConfigDAO dao = new HB_SysConfigDAO();
			SysConfig config = dao.getByKey(key);
			if (config == null){
				response.getWriter().print("配置项不存在");
				return;
			}
			dao.delete(config);
			dao.commit();
			response.getWriter().print(200);
			return;
		}
		response.getWriter().print("配置项不存在");
	}

}
